Zepto(function($) {
  var brandName = sessionStorage.getItem("brandName");
  var brandId = sessionStorage.getItem("brandId");
  var brandUrl = sessionStorage.getItem("brandUrl");
  $("#brandlogoUrl")[0].src =brandUrl;
  $("title").html(brandName);
  $("#BrandTitle").html(brandName);
  window.onload=function () {
    initList();
  }
  /**
   * 上拉加载具体业务实现
   * =====================================================================================================================
   */
  var next = 0;
  // function lowEnough(){
  //   var pageHeight = Math.max(document.body.scrollHeight,document.body.offsetHeight);
  //   var viewportHeight = window.innerHeight ||
  //       document.documentElement.clientHeight ||
  //       document.body.clientHeight || 0;
  //   var scrollHeight = window.pageYOffset ||
  //       document.documentElement.scrollTop ||
  //       document.body.scrollTop || 0;
  //   return pageHeight - viewportHeight - scrollHeight < 20;
  // }
  // function doSomething(){
  //   initList();
  //   pollScroll();//继续循环
  //   $('#spinner').hide();
  // }
  // function checkScroll(){
  //   if(!lowEnough()) return pollScroll();
  //   $('#spinner').show();
  //   setTimeout(doSomething,1000);
  // }
  // function pollScroll(){
  //   setTimeout(checkScroll,1000);
  // }

  /**
   * =====================================================================================================================
   */
  $("#spinner").click(function () {
    initList();
  });

  /**
   * 初始化订单列表
   *
   */
  function initList() {
    $.ajax({
      type: 'GET',
      url: getUrl + '/wxmall/goods/selectBrandGoodsList',
      data: {
        brandId: brandId,
        current: next,
        limit:2
      },
      dataType: 'json',
      timeout: 15000,
      headers: headers("goods.selectBrandGoodsList"),
      context: $('body'),
      success: function(data){
        barndInitList(data);
      },
      error: function(xhr, type){
      }
    })
  }
  $("#barandGoodsList").html("");
  function barndInitList(data) {
      if(!data.success){
        return
      }
      var data2 = data.data;
      var data1 = data2.list;
      next = data2.next;
      var table = document.body.querySelector('.mui-table-view1');
      if(data2.listSize == 0){
        $('#spinner')[0].innerHTML="亲，没有更多了~";
        setTimeout(function () {
          $('#spinner').hide();
        },1000);
      }
      if(data1 != null && data1 != undefined && data1 != ""){
        for(var i = 0; i < data1.length; i++){
          var goodsName = "";
          if(data1[i].goodsName != null){
            goodsName = data1[i].goodsName;
          }
          var wechat_price = "";
          if(data1[i].wechat_price != null){
            wechat_price ="￥" + data1[i].wechat_price;
          }
          //
          var limitPrice = "";
          if(data1[i].limitPrice != null){
            limitPrice ="￥" + data1[i].limitPrice;
          }
          var goodsId = "";
          if(data1[i].goodsId != null){
            goodsId =data1[i].goodsId;
          }
          var goodsId = "";
          if(data1[i].goodsId != null){
            goodsId =data1[i].goodsId;
          }
          //
          var goodsImage = ""
          if(data1[i].goodsImage != null && data1[i].goodsImage.length != 0){
            if(data1[i].goodsImage[0].picUrl != null){
              goodsImage = imgUrl +  data1[i].goodsImage[0].picUrl;
            }
          }
          var li = document.createElement('li');
          li.setAttribute("data-goodId",goodsId);
          li.innerHTML= '<div class="e-video">'+
              '<img src="'+ goodsImage +'">'+
              '</div>'+
              '<div class="specifica-goods">'+
              '<div class="goods-title">'+goodsName+'</div>'+
              '<div class="goods-detail">'+
              '<div class="goods-price">'+
              '<span class="reality-goods-price">'+ wechat_price +'</span>'+
              '<span class="original-goods-price">'+limitPrice+'</span>'+
              '<span class="original-goods-price1"></span>'+
              '</div>'+
              '<div class="add-icon">'+
              '<div class="add-cart"></div>'+
              '<div class="selec-details"></div>'+
              '</div>'+
              '</div>'+
              '</div>';
          table.appendChild(li);
        }
      }
    }
  $(".tab").on("click","div",function () {
    $(".tab>div").removeClass("active");
    $(this).addClass('active');
  });
  $(".tab").on("click",".tab1",function () {
    $(".tab1-cont").css("display","block")
    $(".tab2-cont").css("display","none")
    $(".tab3-cont").css("display","none")
    window.location.href = "/index/index.html"
  })
  $(".tab").on("click",".tab2",function () {
    $(".tab1-cont").css("display","none")
    $(".tab2-cont").css("display","block")
    $(".tab3-cont").css("display","none")
  })
  $(".tab").on("click",".tab3",function () {
    $(".tab1-cont").css("display","none")
    $(".tab2-cont").css("display","none")
    $(".tab3-cont").css("display","block")
  })
  //跳转详情
  $("ul").on("click","li",function () {
    sessionStorage.setItem("brandGoodId", $(this)[0].getAttribute("data-goodId"));
    window.location.href = "/index/bgupGoodsDetails.html"
  })
});